/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package infb.dao;

import infb.modelo.PartesMedicos;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;


@Stateless(mappedName="PartesMedicosEJB")
public class PartesMedicosBean implements PartesMedicosInterfaz {
    @PersistenceContext
    private EntityManager em;

    public void create(PartesMedicos partesMedicos) {
        em.persist(partesMedicos);
    }

    public void edit(PartesMedicos partesMedicos) {
        em.merge(partesMedicos);
    }

    public void remove(PartesMedicos partesMedicos) {
        em.remove(em.merge(partesMedicos));
    }

    public PartesMedicos find(Object id) {
        return em.find(PartesMedicos.class, id);
    }

    public List<PartesMedicos> findAll() {
        return em.createQuery("select object(o) from PartesMedicos as o").getResultList();
    }
     public List<PartesMedicos> ListarHistorialPaciente(Long idPaciente){
     javax.persistence.Query q = em.createNativeQuery("select pm.* from  partes_medicos pm, pacientes p "+
               " WHERE pm.paciente = p.id AND p.id= ?1", PartesMedicos.class)
                .setParameter(1, idPaciente);

       return q.getResultList();
     }
     public List<PartesMedicos> TratamientoActual(Long idPaciente){
     javax.persistence.Query q = em.createNativeQuery("select pm.* from  partes_medicos pm, pacientes p "+
               " WHERE pm.fecha_finalizacion >= sysdate AND pm.paciente=p.id and p.id= ?1", PartesMedicos.class)
                .setParameter(1, idPaciente);

       return q.getResultList();
     }

}
